<?php

include_once("../module/checkA.php");
include_once("../../config.php");
include_once ("../../api/cls_json.php");

session_start();

$admin_user = $_SESSION['username'] !='' ? $_SESSION['username'] : $_SESSION['mid'];



$result = array('error' => 1, 'message' => '', 'content' => '');
$json  = new JSON;

if($admin_user  == ''){
	$result['error'] = "1";
	$result['message'] = "未知错误，请重新登陆操作";
	die($json->encode($result));
	exit;
}

$act=$_REQUEST['act'];

if($act=='client'){
	$name = trim($_REQUEST['name']);
	$phone = trim($_REQUEST['phone']);

	if(empty($name) && empty($phone)){
		$result['error'] = "1";
		$result['message'] = "参数有误";
		die($json->encode($result));
		exit;
	}

	$user_arr = select_one_line_all_items("athlon_member"," phone = '$phone'");
	if($user_arr){
		$result['error'] = "1";
		$result['message'] = "客户已存在";
		die($json->encode($result));
		exit;
	}

		$res1 = do_query(" insert into athlon_member (name,phone) VALUES ('$name','$phone')  ");
		
		if($res1){
			$result['error'] = "0";
			$result['message'] = "保存成功";
		} else{
			$result['error'] = "1";
			$result['message'] = "保存失败";
		}

}else if($act=='unit'){
	$shuihao = trim($_REQUEST['shuihao']);
	$address = trim($_REQUEST['address']);

	if(empty($shuihao) && empty($address)){
		$result['error'] = "1";
		$result['message'] = "参数有误";
		die($json->encode($result));
		exit;
	}

	$unit_arr = select_one_line_all_items("athlon_unit"," shuihao = '$shuihao' ");
	if($unit_arr){
		$result['error'] = "1";
		$result['message'] = "企业已存在";
		die($json->encode($result));
		exit;
	}

		$res1 = do_query(" insert into athlon_unit (shuihao,address) VALUES ('$shuihao','$address')  ");

		if($res1){
			$result['error'] = "0";
			$result['message'] = "保存成功";
		} else{
			$result['error'] = "1";
			$result['message'] = "保存失败";
		}
	}

die($json->encode($result));
exit;	

?>